package com.sherllinhe.batch.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sherllinhe.batch.feign.BusinessFeign;
import com.sherllinhe.common.resp.CommonResp;
import jakarta.annotation.Resource;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * 功能：
 * 作者：Sherllin He
 * 日期：2025/5/23 9:23
 */
@Slf4j
@DisallowConcurrentExecution
@Data
public class DailyTrainJob implements Job {
    @Resource
    BusinessFeign businessFeign;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 增加日志流水号
        MDC.put("LOG_ID", System.currentTimeMillis() + RandomUtil.randomString(3));
        log.info("生成15天后的 每日车次/每日车站/每日车厢/每日座位 开始");
        Date date = new Date();
        DateTime dateTime = DateUtil.offsetDay(date, 15);
        Date offsetDate = dateTime.toJdkDate();
        CommonResp<Object> commonResp = businessFeign.genDaily(offsetDate);
        log.info("生成15天后的 每日车次/每日车站/每日车厢/每日座位 结束，结果：{}",commonResp);
    }
}
